package com.rongshu.view.discovery.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.utils.Common;
import com.rongshu.utils.UserInfoUtils;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetView;
import com.rongshu.view.discovery.bean.EventListResponse;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;
import rx.functions.Action0;

/**
 * created by zhengweis on 2019/4/29.
 * description：
 */
public class MoreEventPresenter extends BasePresenter<INetView> {

    public MoreEventPresenter(Context context) {
        super(context);
    }

    public void getEvents(int pageIndex, int pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", UserInfoUtils.getUserId());
        map.put("pageIndex", pageIndex);
        map.put("pageSize", pageSize);
        RetorfitService.getEvents(UserInfoUtils.getUserId(), pageIndex, pageSize, Common.encryptionSign(map))
                .compose(getView().<EventListResponse>bindToLife())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {

                    }
                })
                .subscribe(new Subscriber<EventListResponse>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(EventListResponse object) {
                        if (object.getErrCode() == 0) {
                            getView().success(object, 0);
                        }
                    }
                });
    }
}
